//
//  Image.m
//  costa-postcards
//
//  Created by 黄 鹏霄 on 12-12-13.
//  Copyright (c) 2012年 test. All rights reserved.
//

#import "Image.h"
#import "AFAppDotNetAPIClient.h"
#import "AFJSONRequestOperation.h"

@implementation Image

+ (void)uploadImage:(NSString *) imagePath
{
    AFAppDotNetAPIClient *client = [AFAppDotNetAPIClient sharedClient];
    
    NSString *uploadPath = @"rest/img/upload";
    
    NSMutableURLRequest *request =  [client multipartFormRequestWithMethod:@"POST" path:uploadPath parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:UIImagePNGRepresentation([UIImage imageNamed:@"1.jpg"]) name:@"file" fileName:@"1.jpg" mimeType:@"image/jpeg"];
    }];
    
    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        NSLog(@"success,%@",JSON);
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
        NSLog(@"failure,%@",JSON);
        NSLog(@"status:%d",response.statusCode);
    }];
    
    [operation start];
}


@end
